"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.update = exports.create = void 0;
function create(Model, idKey = 'id') {
    return async function __create(data) {
        let dbModel = null;
        try {
            if (data[idKey]) {
                dbModel = await Model.findOne({ where: { [idKey]: data[idKey] } });
            }
            if (!dbModel) {
                dbModel = Object.assign(new Model(), data);
                dbModel.createTime = Date.now().toString();
                dbModel.lastActiveTime = Date.now().toString();
                dbModel = await dbModel.save();
            }
        }
        catch (error) {
            console.error(error);
            throw new Error(error);
        }
        return dbModel;
    };
}
exports.create = create;
function update(Modal, idKey = 'id') {
    return async function __update(data = {}) {
        let dbModel = null;
        try {
            dbModel = await Modal.findOne({ where: { [idKey]: data[idKey] } });
            if (dbModel) {
                dbModel = Object.assign(dbModel, data);
                dbModel.lastActiveTime = Date.now().toString();
                dbModel = await Modal.save();
            }
        }
        catch (error) {
            console.error(error);
            throw new Error(error);
        }
        return dbModel;
    };
}
exports.update = update;
